home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / lib / tcl / SplitList.man < prev    next >
Encoding:
Text File  |  1992-08-07  |  9.8 KB  |  335 lines

  1. '\"
  2. '\" Copyright 1989-1991 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. '\" $Header: /user6/ouster/tcl/man/RCS/SplitList.man,v 1.8 92/03/28 14:21:13 ouster Exp $ SPRITE (Berkeley)
  11. '\" 
  12. .\" The definitions below are for supplemental macros used in Sprite
  13. .\" manual entries.
  14. .\"
  15. .\" .HS name section [date [version]]
  16. .\"    Replacement for .TH in other man pages.  See below for valid
  17. .\"    section names.
  18. .\"
  19. .\" .AP type name in/out [indent]
  20. .\"    Start paragraph describing an argument to a library procedure.
  21. .\"    type is type of argument (int, etc.), in/out is either "in", "out",
  22. .\"    or "in/out" to describe whether procedure reads or modifies arg,
  23. .\"    and indent is equivalent to second arg of .IP (shouldn't ever be
  24. .\"    needed;  use .AS below instead)
  25. .\"
  26. .\" .AS [type [name]]
  27. .\"    Give maximum sizes of arguments for setting tab stops.  Type and
  28. .\"    name are examples of largest possible arguments that will be passed
  29. .\"    to .AP later.  If args are omitted, default tab stops are used.
  30. .\"
  31. .\" .BS
  32. .\"    Start box enclosure.  From here until next .BE, everything will be
  33. .\"    enclosed in one large box.
  34. .\"
  35. .\" .BE
  36. .\"    End of box enclosure.
  37. .\"
  38. .\" .VS
  39. .\"    Begin vertical sidebar, for use in marking newly-changed parts
  40. .\"    of man pages.
  41. .\"
  42. .\" .VE
  43. .\"    End of vertical sidebar.
  44. .\"
  45. .\" .DS
  46. .\"    Begin an indented unfilled display.
  47. .\"
  48. .\" .DE
  49. .\"    End of indented unfilled display.
  50. .\"
  51. '\"    # Heading for Sprite man pages
  52. .de HS
  53. .if '\\$2'cmds'       .TH \\$1 1 \\$3 \\$4
  54. .if '\\$2'lib'        .TH \\$1 3 \\$3 \\$4
  55. .if '\\$2'tcl'        .TH \\$1 3 \\$3 \\$4
  56. .if '\\$2'tk'         .TH \\$1 3 \\$3 \\$4
  57. .if t .wh -1.3i ^B
  58. .nr ^l \\n(.l
  59. .ad b
  60. ..
  61. '\"    # Start an argument description
  62. .de AP
  63. .ie !"\\$4"" .TP \\$4
  64. .el \{\
  65. .   ie !"\\$2"" .TP \\n()Cu
  66. .   el          .TP 15
  67. .\}
  68. .ie !"\\$3"" \{\
  69. .ta \\n()Au \\n()Bu
  70. \&\\$1    \\fI\\$2\\fP    (\\$3)
  71. .\".b
  72. .\}
  73. .el \{\
  74. .br
  75. .ie !"\\$2"" \{\
  76. \&\\$1    \\fI\\$2\\fP
  77. .\}
  78. .el \{\
  79. \&\\fI\\$1\\fP
  80. .\}
  81. .\}
  82. ..
  83. '\"    # define tabbing values for .AP
  84. .de AS
  85. .nr )A 10n
  86. .if !"\\$1"" .nr )A \\w'\\$1'u+3n
  87. .nr )B \\n()Au+15n
  88. .\"
  89. .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
  90. .nr )C \\n()Bu+\\w'(in/out)'u+2n
  91. ..
  92. '\"    # BS - start boxed text
  93. '\"    # ^y = starting y location
  94. '\"    # ^b = 1
  95. .de BS
  96. .br
  97. .mk ^y
  98. .nr ^b 1u
  99. .if n .nf
  100. .if n .ti 0
  101. .if n \l'\\n(.lu\(ul'
  102. .if n .fi
  103. ..
  104. '\"    # BE - end boxed text (draw box now)
  105. .de BE
  106. .nf
  107. .ti 0
  108. .mk ^t
  109. .ie n \l'\\n(^lu\(ul'
  110. .el \{\
  111. .\"    Draw four-sided box normally, but don't draw top of
  112. .\"    box if the box started on an earlier page.
  113. .ie !\\n(^b-1 \{\
  114. \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  115. .\}
  116. .el \}\
  117. \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  118. .\}
  119. .\}
  120. .fi
  121. .br
  122. .nr ^b 0
  123. ..
  124. '\"    # VS - start vertical sidebar
  125. '\"    # ^Y = starting y location
  126. '\"    # ^v = 1 (for troff;  for nroff this doesn't matter)
  127. .de VS
  128. .mk ^Y
  129. .ie n 'mc \s12\(br\s0
  130. .el .nr ^v 1u
  131. ..
  132. '\"    # VE - end of vertical sidebar
  133. .de VE
  134. .ie n 'mc
  135. .el \{\
  136. .ev 2
  137. .nf
  138. .ti 0
  139. .mk ^t
  140. \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
  141. .sp -1
  142. .fi
  143. .ev
  144. .\}
  145. .nr ^v 0
  146. ..
  147. '\"    # Special macro to handle page bottom:  finish off current
  148. '\"    # box/sidebar if in box/sidebar mode, then invoked standard
  149. '\"    # page bottom macro.
  150. .de ^B
  151. .ev 2
  152. 'ti 0
  153. 'nf
  154. .mk ^t
  155. .if \\n(^b \{\
  156. .\"    Draw three-sided box if this is the box's first page,
  157. .\"    draw two sides but no top otherwise.
  158. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  159. .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  160. .\}
  161. .if \\n(^v \{\
  162. .nr ^x \\n(^tu+1v-\\n(^Yu
  163. \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
  164. .\}
  165. .bp
  166. 'fi
  167. .ev
  168. .if \\n(^b \{\
  169. .mk ^y
  170. .nr ^b 2
  171. .\}
  172. .if \\n(^v \{\
  173. .mk ^Y
  174. .\}
  175. ..
  176. '\"    # DS - begin display
  177. .de DS
  178. .RS
  179. .nf
  180. .sp
  181. ..
  182. '\"    # DE - end display
  183. .de DE
  184. .fi
  185. .RE
  186. .sp .5
  187. ..
  188. .HS Tcl_SplitList tcl
  189. .BS
  190. .SH NAME
  191. Tcl_SplitList, Tcl_Merge, Tcl_ScanElement, Tcl_ConvertElement \- manipulate Tcl lists
  192. .SH SYNOPSIS
  193. .nf
  194. \fB#include <tcl.h>\fR
  195. .sp
  196. int
  197. \fBTcl_SplitList\fR(\fIinterp, list, argcPtr, argvPtr\fR)
  198. .sp
  199. char *
  200. \fBTcl_Merge\fR(\fIargc, argv\fR)
  201. .sp
  202. .VS
  203. int
  204. \fBTcl_ScanElement\fR(\fIsrc, flagsPtr\fR)
  205. .sp
  206. int
  207. \fBTcl_ConvertElement\fR(\fIsrc, dst, flags\fR)
  208. .VE
  209. .SH ARGUMENTS
  210. .AS Tcl_Interp ***argvPtr
  211. .AP Tcl_Interp *interp out
  212. Interpreter to use for error reporting.
  213. .AP char *list in
  214. Pointer to a string with proper list structure.
  215. .AP int *argcPtr out
  216. Filled in with number of elements in \fIlist\fR.
  217. .AP char ***argvPtr out
  218. \fI*argvPtr\fR will be filled in with the address of an array of
  219. pointers to the strings that are the extracted elements of \fIlist\fR.
  220. There will be \fI*argcPtr\fR valid entries in the array, followed by
  221. a NULL entry.
  222. .AP int argc in
  223. Number of elements in \fIargv\fR.
  224. .AP char **argv in
  225. Array of strings to merge together into a single list.
  226. Each string will become a separate element of the list.
  227. .AP char *src in
  228. .VS
  229. String that is to become an element of a list.
  230. .AP int *flagsPtr in
  231. Pointer to word to fill in with information about \fIsrc\fR.
  232. The value of *\fIflagsPtr\fR must be passed to \fBTcl_ConvertElement\fR.
  233. .AP char *dst in
  234. Place to copy converted list element.  Must contain enough characters
  235. to hold converted string.
  236. .AP int flags in
  237. Information about \fIsrc\fR. Must be value returned by previous
  238. call to \fBTcl_ScanElement\fR, possibly OR-ed
  239. with \fBTCL_DONT_USE_BRACES\fR.
  240. .VE
  241. .BE
  242.  
  243. .SH DESCRIPTION
  244. .PP
  245. These procedures may be used to disassemble and reassemble Tcl lists.
  246. \fBTcl_SplitList\fR breaks a list up into its constituent elements,
  247. returning an array of pointers to the elements using
  248. \fIargcPtr\fR and \fIargvPtr\fR.
  249. While extracting the arguments, \fBTcl_SplitList\fR obeys the usual
  250. rules for backslash substitutions and braces.  The area of
  251. memory pointed to by \fI*argvPtr\fR is dynamically allocated;  in
  252. addition to the array of pointers, it
  253. also holds copies of all the list elements.  It is the caller's
  254. responsibility to free up all of this storage by calling
  255. .DS
  256. \fBfree\fR((char *) \fI*argvPtr\fR)
  257. .DE
  258. when the list elements are no longer needed.
  259. .PP
  260. \fBTcl_SplitList\fR normally returns \fBTCL_OK\fR, which means the list was
  261. successfully parsed.
  262. If there was a syntax error in \fIlist\fR, then \fBTCL_ERROR\fR is returned
  263. and \fIinterp->result\fR will point to an error message describing the
  264. problem.
  265. If \fBTCL_ERROR\fR is returned then no memory is allocated and \fI*argvPtr\fR
  266. is not modified.
  267. .PP
  268. \fBTcl_Merge\fR is the inverse of \fBTcl_SplitList\fR:  it
  269. takes a collection of strings given by \fIargc\fR
  270. and \fIargv\fR and generates a result string
  271. that has proper list structure.
  272. This means that commands like \fBindex\fR may be used to
  273. extract the original elements again.
  274. In addition, if the result of \fBTcl_Merge\fR is passed to \fBTcl_Eval\fR,
  275. it will be parsed into \fIargc\fR words whose values will
  276. be the same as the \fIargv\fR strings passed to \fBTcl_Merge\fR.
  277. \fBTcl_Merge\fR will modify the list elements with braces and/or
  278. backslashes in order to produce proper Tcl list structure.
  279. The result string is dynamically allocated
  280. using \fBmalloc()\fR;  the caller must eventually release the space
  281. using \fBfree()\fR.
  282. .PP
  283. If the result of \fBTcl_Merge\fR is passed to \fBTcl_SplitList\fR,
  284. the elements returned by \fBTcl_SplitList\fR will be identical to
  285. those passed into \fBTcl_Merge\fR.
  286. However, the converse is not true:  if \fBTcl_SplitList\fR
  287. is passed a given string, and the resulting \fIargc\fR and
  288. \fIargv\fR are passed to \fBTcl_Merge\fR, the resulting string
  289. may not be the same as the original string passed to \fBTcl_SplitList\fR.
  290. This is because \fBTcl_Merge\fR may use backslashes and braces
  291. differently than the original string.
  292. .PP
  293. .VS
  294. \fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR are the
  295. procedures that do all of the real work of \fBTcl_Merge\fR.
  296. \fBTcl_ScanElement\fR scans its \fIsrc\fR argument
  297. and determines how to use backslashes and braces
  298. when converting it to a list element.
  299. It returns an overestimate of the number of characters
  300. required to represent \fIsrc\fR as a list element, and
  301. it stores information in \fI*flagsPtr\fR that is needed
  302. by \fBTcl_ConvertElement\fR.
  303. .PP
  304. \fBTcl_ConvertElement\fR is a companion procedure to \fBTcl_ScanElement\fR.
  305. It does the actual work of converting a string to a list element.
  306. Its \fIflags\fR argument must be the same as the value returned
  307. by \fBTcl_ScanElement\fR.
  308. \fBTcl_ConvertElement\fR writes a proper list element to memory
  309. starting at *\fIdst\fR and returns a count of the total number
  310. of characters written, which will be no more than the result
  311. returned by \fBTcl_ScanElement\fR.
  312. \fBTcl_ConvertElement\fR writes out only the actual list element
  313. without any leading or trailing spaces: it is up to the caller to
  314. include spaces between adjacent list elements.
  315. .PP
  316. \fBTcl_ConvertElement\fR uses one of two different approaches to
  317. handle the special characters in \fIsrc\fR.  Wherever possible, it
  318. handles special characters by surrounding the string with braces.
  319. This produces clean-looking output, but can't be used in some situations,
  320. such as when \fIsrc\fR contains unmatched braces.
  321. In these situations, \fBTcl_ConvertElement\fR handles special
  322. characters by generating backslash sequences for them.
  323. The caller may insist on the second approach by OR-ing the
  324. flag value returned by \fBTcl_ScanElement\fR with
  325. \fBTCL_DONT_USE_BRACES\fR.
  326. Although this will produce an uglier result, it is useful in some
  327. special situations, such as when \fBTcl_ConvertElement\fR is being
  328. used to generate a portion of an argument for a Tcl command.
  329. In this case, surrounding \fIsrc\fR with curly braces would cause
  330. the command not to be parsed correctly.
  331. .VE
  332.  
  333. .SH KEYWORDS
  334. backslash, convert, element, list, merge, split, strings
  335.